<script type="text/javascript">

//Redirect to the correct page URL if we have session storage variables in cache.
          function getURLVariable(variable){
       var query = window.location.search.substring(1);
       var vars = query.split("&");
       for (var i=0;i<vars.length;i++) {
               var pair = vars[i].split("=");
               if(pair[0] == variable){return pair[1];}
       }
                   return(false);
        }
                
     		function checkURLelements(variable){            
               if(getURLVariable(variable)==sessionStorage[variable]){   
			   	//do nothing because we are on the correct URL
			   }else{
				   if(getURLVariable(variable)!="undefined"){
					   
					   sessionStorage[variable]=getURLVariable(variable);
					   
				   }else{
					//refresh page with correct URL
					if(getURLVariable(variable)=="undefined"){
						
						if(sessionStorage[variable]=="undefined"){
							window.location.href = "chartIndicators.php?displays=" +sessionStorage['displays']+ "&advSymbol=" + sessionStorage['advSymbol']+ "&advStartDate="+ sessionStorage['advStartDate']+ "&advType="+sessionStorage["advType"]+ "&advEndDate="+ sessionStorage['advEndDate']+ "&technicals="+sessionStorage['technicals'];;
						}
					}else{
							window.location.href = "chartIndicators.php?displays=" +sessionStorage['displays']+ "&advSymbol=" + sessionStorage['advSymbol']+ "&advStartDate="+ sessionStorage['advStartDate']+ "&advType="+sessionStorage["advType"]+ "&advEndDate="+ sessionStorage['advEndDate']+ "&technicals="+sessionStorage['technicals'];;
					}
					
			   }
			   }
			}
			
			//check all of the possible session Storage elements
			checkURLelements("displays");checkURLelements("advSymbol");checkURLelements("advStartDate");checkURLelements("advType");checkURLelements("advEndDate");checkURLelements("technicals");
			
				
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
require_once("../Scripts/DatabaseConnect.php");
require_once("../Scripts/UpdateStocks.php");//Checks if we need to update the database with new market data.

//Check if we need local server or remote server
$con=Remoteconnect();
if($con==null){
	$con=Localconnect();	
}
//Display the last update date and current date and time.
$lastUpdate="";
$result = mysqli_query($con,"SELECT * FROM  `time`");

while($row = mysqli_fetch_array($result)) {
	$lastUpdate=$row['LastUpdate'];

  
}

$date = date('m-d-Y h:i:s a', time());//gets current date and time of server.
echo"Date: $date, Last Update: $lastUpdate";
session_start();
?>






<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN" dir="ltr">
<head profile="http://gmpg.org/xfn/11">
<title>J&J Free Stock backtesting</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="imagetoolbar" content="no" />
<link rel="stylesheet" href="businesstoday/styles/layout.css" type="text/css" />
</head>
<body id="top" onLoad="CorrectURl()" >
<div class="wrapper col1">
  <div id="header">
    <img src="../Images/the-top-5-high-volume-trading-stocks-of-the-week_1118_437849_0_14042581_500.jpg" alt="" width="240" height="162" />
    <div id="logo">
      <h1>J&amp;J Free Stock Backtesting    </h1>
    </div>
    <div id="newsletter">
    <div id="login" style="display:block; min-height:50px; min-width:600px;">
      <p><a href="#">Lost your password?</a> <a href="register.php">Register</a>

      </p>
      
      <form action="../Scripts/authenticate.php" method="post" >
      
        <fieldset>
          <legend>NewsLetter</legend>
          <table>
            <tr>
              <td>Name:</td>
              <td><input type="email" name="email" required id="email" /></td>
              <td>Password:</td>
              <td><input type="password" name="password" required id="password" /></td>
              <td><input type="submit" name="news_go" id="news_go" value="Login" /></td>
            </tr>
          </table>
        </fieldset>
      </form>


      </div>
      
      <?php
	  //Wrong password message
      if (isset($_SESSION['msg'])) {
	echo "<p style='color:red'>".$_SESSION['msg']."</p>"; 
	//remove the message since it has been displayed.
	unset($_SESSION['msg']);
	}
	?>
    
   	<?php
	//logout button
    if (isset($_SESSION['msgG'])) {
		echo"<form>";
		echo "<p style='color:green'>".$_SESSION['msgG']."</p>"; 
		echo '<input type="button" name="logout" id="logout" value="Logout" onClick="location.href=\'../Scripts/Logout.php\'"/>'; 
		echo"</form>";
	}
	
?> 
  

    </div>
    <br class="clear" />
  </div>
</div>

<div class="wrapper col2">
  <div id="topbar">
    <div id="topnav">
      <ul>
        <li class="active">
         
              <li><a href="index.php">Home Page</a></li>
              <li id="portfolio" style="display:none"><a href="portfolio.php">Stock Portfolio</a></li>
              <li id="stockMonitoring" style="display:none"><a href="stockMonitoring.php">Stock Monitoring</a></li>
              <li><a href="stockbacktest.php">Stock Backtest</a></li>
              <li><a href="charts.php">Stock Charts</a>
               <ul>
            <li><a href="chartDifShares.php">Stock Prices Comparision Chart</a></li>
            <li><a href="chartIndicators.php">Stock Technical Analysis Chart</a></li>
         
          </ul>
        </li>

        
  </li>      
        
        
      </ul>
    </div>
 <script type="text/javascript">
 //Hides/Shows navigation bar links based on logged in status
	  var check = <?php echo json_encode(isset($_SESSION['email'])); ?>;
	  
	  if(check==true){
		  document.getElementById("login").style.display="none";
		  document.getElementById("portfolio").style.display="block";
		  document.getElementById("stockMonitoring").style.display="block";

	  }else{
		  document.getElementById("login").style.display="block";
		  document.getElementById("stockMonitoring").style.display="none";
		  document.getElementById("portfolio").style.display="none";
		  
	  }
	 
 </script>
 
       
    <br class="clear" />
  </div>
</div>
<div class="wrapper col3">  <div id="intro">
    

   
    <div class="fl_right"></div>
    <br class="clear" />
  </div>
</div>
<div class="wrapper col4"></div>
<div class="wrapper col5">
  <div id="container">

      
            <link rel="stylesheet" type="text/css" href="../Styles/style.css" />
  <?php
	 require_once("../Scripts/chartProcess.php");//obtains data from database
  ?>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
		
      google.load("visualization", "1", {packages:["corechart"]});

	  google.setOnLoadCallback(indicatorDrawChart);
	  google.setOnLoadCallback(RSIDrawChart);
	  google.setOnLoadCallback(MacDDrawChart);
	  google.setOnLoadCallback(ROCDrawChart);
	  google.setOnLoadCallback(OBVDrawChart);
	  google.setOnLoadCallback(WilliamRDrawChart);
	  google.setOnLoadCallback(MTMDrawChart);
	  google.setOnLoadCallback(FastSTCDrawChart);
	  google.setOnLoadCallback(DMIDrawChart);
	  google.setOnLoadCallback(PVTDrawChart);

	  var colours=[];//array used to store colour numbers



function addSymbol(){		

		//Advanced chart symbol
		var advSymbol=document.getElementById("advSymbol")
		if(advSymbol.value!="none"){

		window.sessionStorage.setItem("advSymbol",advSymbol.value);
		
		}
		
			
		//refresh page if we have either of the symbols
		if(sessionStorage['advSymbol']){		
		window.location.href = "chartIndicators.php?displays=" +sessionStorage['displays']+ "&advSymbol=" + sessionStorage['advSymbol']+ "&advStartDate="+ sessionStorage['advStartDate']+ "&advType="+sessionStorage["advType"]+ "&advEndDate="+ sessionStorage['advEndDate']+ "&technicals="+sessionStorage['technicals'];;
		}
		
	  }


function advProcessType(){
var type= document.getElementById('advType');
if(type.value!="none"){
	if(sessionStorage["advType"]){
		sessionStorage["advType"]=type.value;	
	}
	else{
		window.sessionStorage.setItem("advType",type.value);	
	}
}else{
	window.sessionStorage.setItem("advType","Close");	
}
		window.location.href = "chartIndicators.php?displays=" +sessionStorage['displays']+ "&advSymbol=" + sessionStorage['advSymbol']+ "&advStartDate="+ sessionStorage['advStartDate']+ "&advType="+sessionStorage["advType"]+ "&advEndDate="+ sessionStorage['advEndDate']+ "&technicals="+sessionStorage['technicals'];;

}
	  

function processAdvDate(){
		//advanced start and end date
		var advStartDate=document.getElementById("advStartDate").value;
		var advEndDate=document.getElementById("advEndDate").value;
		
		window.sessionStorage.setItem("advStartDate", advStartDate);
		window.sessionStorage.setItem("advEndDate", advEndDate);
		
		if(sessionStorage['advStartDate']&&sessionStorage['advEndDate']){		
		window.location.href = "chartIndicators.php?displays=" +sessionStorage['displays']+ "&advSymbol=" + sessionStorage['advSymbol']+ "&advStartDate="+ sessionStorage['advStartDate']+ "&advType="+sessionStorage["advType"]+ "&advEndDate="+ sessionStorage['advEndDate']+ "&technicals="+sessionStorage['technicals'];;
		}
		  
		  
	  }
	  
function getRandomColor() {
	var colours= ['#3366CC','#DC3912','#FF9900','#109618','#990099','#0099C6','#66AA00','#B82E2E','#316395','#994499','#22AA99','#AAAA11','#6633CC',
	'#E67300','#8B0707','#329262','#5574A6'];
	var i= Math.floor((Math.random() * 16) + 0);
    return colours[i];
}

function indicatorDrawChart() {//Indicator Price
		//ensure we have all of the required variables
		if(sessionStorage['advStartDate']&&sessionStorage['advEndDate']&&sessionStorage['advSymbol']&&sessionStorage['displays']&&sessionStorage['advType']){


		document.getElementById("indicatorChart_div").style.display="block";//show the chart div

			var localdisplays=sessionStorage['displays'].split(",");

		  // Create and populate the data table.
		  var time = <?php echo json_encode($advDates); ?>;
  		  var Symboldata=<?php echo json_encode($advSymbolArray); ?>;
		 var smaData=<?php echo json_encode($smaArray); ?>;


  var data = new google.visualization.DataTable();
  data.addColumn('date', 'days');
  colours.push(getRandomColor());
		data.addColumn('number',sessionStorage['advSymbol']);	
		
		
		
		
		
		//add a column for each displays
		for(i=0;i<localdisplays.length;i++){
			var splitdisplay=localdisplays[i].split("/");
			if(splitdisplay.length>2&&splitdisplay[0]!="SAR"&&splitdisplay[0]!="Bollinger"){
				for(x=1;x<splitdisplay.length;x++){
					
					data.addColumn('number',splitdisplay[0]+"/"+splitdisplay[x]);
					colours.push(getRandomColor());
				
				}
				
				
				
			}else if(splitdisplay[0]=="Bollinger"){
				data.addColumn('number',"BbandUpper");
				colours.push('#3B3EAC');
				data.addColumn('number',"BbandMiddle");
				colours.push('#DD4477');
				data.addColumn('number',"BbandLower");
				colours.push('#3B3EAC');
				
			}
			else{
				data.addColumn('number',localdisplays[i]);	
				colours.push(getRandomColor());
			}
		}
		
		
			
		
	  
	//for the length of the Symbol data array
	console.log("time: "+time.length);	
  for(i = 0; i < time.length; i++){
	  
	  //add row based on count of symbols
	var row=[];
	
	
	
	var date= time[i].split("-");

	row.push(new Date(date[0], date[1]-1,date[2]));

	row.push(Number(Symboldata[i]));
	
	//add a column for each displays
	for(x=0;x<localdisplays.length;x++){
		var splitdisplay=localdisplays[x].split("/");
		
		if(splitdisplay[0]=="SMA"){
			var smaData=<?php echo json_encode($smaArray); ?>;
			if(splitdisplay.length>2){
				for(j=1;j<splitdisplay.length;j++){
					row.push(Number(smaData[j-1][i+(splitdisplay[j]-1)]));
				}
				}else{
			
			//add SMA data to row	
			
			console.log("SMA");
			console.log(smaData);
				row.push(Number(smaData[0][i+(splitdisplay[1]-1)]));
				}
		}
		if(splitdisplay[0]=="EMA"){
			var emaData=<?php echo json_encode($emaArray); ?>;
			if(splitdisplay.length>2){
				for(j=1;j<splitdisplay.length;j++){
					row.push(Number(emaData[j-1][i+(splitdisplay[j]-1)]));
				}
				}else{
			
			//add EMA data to row	
			
			console.log("EMA");
			console.log(emaData);
				row.push(Number(emaData[0][i+(splitdisplay[1]-1)]));
				}
		}
		if(splitdisplay[0]=="WMA"){
			var wmaData=<?php echo json_encode($wmaArray); ?>;
			if(splitdisplay.length>2){
				for(j=1;j<splitdisplay.length;j++){
					row.push(Number(wmaData[j-1][i+(splitdisplay[j]-1)]));
					
				}
				}else{
			
			//add WMA data to row	
			
			//console.log("SMA");
			//console.log(smaData);
				row.push(Number(wmaData[0][i+(splitdisplay[1]-1)]));
				}
		}
		
		if(splitdisplay[0]=="SAR"){
			var sarData=<?php echo json_encode($sarArray); ?>;
			console.log("SAR");
			console.log(sarData);
			row.push(Number(sarData[0][i+1]));
				
		}
		if(splitdisplay[0]=="Bollinger"){
			var bollingerData=<?php echo json_encode($bollingerArray); ?>;
			console.log(bollingerData);
			row.push(Number(bollingerData[0][0][i+(splitdisplay[1]-1)]));
			row.push(Number(bollingerData[0][1][i+(splitdisplay[1]-1)]));
			row.push(Number(bollingerData[0][2][i+(splitdisplay[1]-1)]));
				
		}
		
		
				
	}

	
	
    data.addRow(row);

	
  
		}
		
		var Min=Math.min.apply(Math, Symboldata);
		var Max=Math.max.apply(Math, Symboldata);
		console.log(Min);
		console.log(Max);
        var options = {
          title: 'Compare '+sessionStorage['advSymbol']+' Prices With Indicators',
		  
						  
          hAxis: {title: 'Day',  titleTextStyle: {color: '#333'}},
		  
          vAxis: {title: 'Prices', minValue: Min, maxValue: Max},
			explorer: {axis:'both',
        	maxZoomin:0.25,
        	keepInBounds: true
    	},
		  
		  colors: colours
		  
		  
        };
		
        var chart = new google.visualization.LineChart(document.getElementById('indicatorChart_div'));
        chart.draw(data, options);
      

	  
	  
}
//Draw Price of symbol:
else{
	if(sessionStorage['advStartDate']&&sessionStorage['advEndDate']&&sessionStorage['advSymbol']&&sessionStorage['advType']){


		document.getElementById("indicatorChart_div").style.display="block";//show the chart div

                
                  
  var time = <?php echo json_encode($advDates); ?>;
  var Symboldata=<?php echo json_encode($advSymbolArray); ?>;;
 
  
  console.log("dates");
  console.log(time);
  console.log("Symboldata");
  console.log(Symboldata);

  var data = new google.visualization.DataTable();
  data.addColumn('date', 'days');
  
        //add column for each symbol
        
        var localsymbols=sessionStorage['advSymbol'];
        
      
       data.addColumn('number',localsymbols);       
                
        
          
        //for the length of the Symbol data array
                
        console.log("time: "+time.length);      
  for(i = 0; i < time.length; i++){
          
          //add row based on count of symbols
        var row=[];
        var index=0;
        
        var date= time[i].split("-");
        row.push(new Date(date[0], date[1]-1,date[2]));
        
        
        row.push(Number(Symboldata[i]));
        index+=1;
        
        
    data.addRow(row);
        console.log("row");
        console.log(row);
        
  }
                }
  console.log(data);
                var Min=Math.min.apply(Math, Symboldata);
                var Max=Math.max.apply(Math, Symboldata);
                console.log(Min);
                console.log(Max);
        var options = {
          title: 'Stock Prices',
          hAxis: {title: 'Day',  titleTextStyle: {color: '#333'}},
          vAxis: {title: 'End price', minValue: Min},
                  explorer: {axis:'both',
          maxZoomin:0.25,
          keepInBounds: true
                  }
        };
                
        var chart = new google.visualization.AreaChart(document.getElementById('indicatorChart_div'));
        chart.draw(data, options);
	
	
	
}

}  
function ProcessDisplay(){
			//Check which boxes are checked:
			var SMA =document.getElementById('SMA');
			var WMA =document.getElementById('WMA');
			var EMA =document.getElementById('EMA');
			var SAR =document.getElementById('SAR');
			var Bollinger =document.getElementById('Bollinger');
			
			//get the time period
			var SMAn =document.getElementById('SMAn');
			var WMAn =document.getElementById('WMAn');
			var EMAn =document.getElementById('EMAn');
			var SARn =document.getElementById('SARn');
			var Bollingern =document.getElementById('Bollingern');
			
			//Create an array of checked boxes to be displayed.
			var displays =[];
			
			//check if displays array is already in local cache
			
			if(sessionStorage['displays']){
				//add local storage displays to the displays array
				var localdisplays=sessionStorage['displays'].split(",");
				for(i=0;i<localdisplays.length;i++){
					displays.push(localdisplays[i]);	
				
				}
			}
		  
			if(SMA.checked==true){
				//ensure that their is only one SMA in the dispalys array
				for(var i=0;i<displays.length;i++){
					var displaycheck = displays[i].split("/");
					if(displaycheck[0]=="SMA"){
						displays.splice(i,1);		
					}
				}
				
				//var validate =/\d+\//;
				
				//alert(validate.test('10'));
				//if(validate.test(SMAn.value)==true){
					//CHECK IF VALID
					if(SMAn.value==""){
						displays.push("SMA/20");
					}else{
					displays.push("SMA/"+SMAn.value);
					}
				//}else{
					
					//displays.push("SMA/20");	
				//}
	
			}else{
				if(displays.indexOf("SMA/"+SMAn.value)>-1){
					displays.splice(displays.indexOf("SMA/"+SMAn.value), 1);//remove from displays array
				}
				
					
			}

			if(WMA.checked==true){
				//ensure that their is only one WMA in the dispalys array
				for(var i=0;i<displays.length;i++){
					var displaycheck = displays[i].split("/");
					if(displaycheck[0]=="WMA"){
						displays.splice(i,1);		
					}
				}
				//if(WMAn.value>1){
					if(WMAn.value==""){
						displays.push("WMA/20");
					}else{
					displays.push("WMA/"+WMAn.value);
					}
				//}else{
					//displays.push("WMA/20");	
				//}
				
			}else{
				if(displays.indexOf("WMA/"+WMAn.value)>-1){
					displays.splice(displays.indexOf("WMA/"+WMAn.value), 1);//remove from displays array
				}
				
			}
			
			if(EMA.checked==true){
				//ensure that their is only one EMA in the dispalys array
				for(var i=0;i<displays.length;i++){
					var displaycheck = displays[i].split("/");
					if(displaycheck[0]=="EMA"){
						displays.splice(i,1);		
					}
				}
				//if(EMAn.value>1){
					if(EMAn.value==""){
						displays.push("EMA/20");
					}else{
					displays.push("EMA/"+EMAn.value);
					}
				//}else{
					//displays.push("EMA/20");	
				//}
				
			}else{
				if(displays.indexOf("EMA/"+EMAn.value)>-1){
					displays.splice(displays.indexOf("EMA/"+EMAn.value), 1);//remove from displays array
				}
				
			}
			
			if(SAR.checked==true){
				//ensure that their is only one SAR in the dispalys array
				for(var i=0;i<displays.length;i++){
					var displaycheck = displays[i].split("/");
					if(displaycheck[0]=="SAR"){
						displays.splice(i,1);		
					}
				}
				//if(SARn.value>1){
					if(SARn.value==""){
						displays.push("SAR/0.02/0.2");
					}else{
					displays.push("SAR/"+SARn.value);
					}
				//}else{
				//	displays.push("SAR/20");	
				//}
				
			}else{
				if(displays.indexOf("SAR/"+SARn.value)>-1){
					displays.splice(displays.indexOf("SAR/"+SARn.value), 1);//remove from displays array
				}
				
			}
			
			if(Bollinger.checked==true){
				//ensure that their is only one Bollinger in the dispalys array
				for(var i=0;i<displays.length;i++){
					var displaycheck = displays[i].split("/");
					if(displaycheck[0]=="Bollinger"){
						displays.splice(i,1);		
					}
				}
				//if(Bollingern.value>1){
					if(Bollingern.value==""){
						displays.push("Bollinger/20/2");
					}else{
					displays.push("Bollinger/"+Bollingern.value);
					}
				//}else{
					//displays.push("Bollinger/20");	
				//}
				
			}else{
				if(displays.indexOf("Bollinger/"+Bollingern.value)>-1){
					displays.splice(displays.indexOf("Bollinger/"+Bollingern.value), 1);//remove from displays array
				}
				
			}
			

				//remove duplicates if any
				displays = displays.filter(function(elem, pos, self) {
				return self.indexOf(elem) == pos;
				});
				
			
			
			
			//Add Array of displays to local storage
			window.sessionStorage.setItem("displays", displays);
			
			//Refresh page to run the php and obtain the data for the displays

		window.location.href = "chartIndicators.php?displays=" +sessionStorage['displays']+ "&advSymbol=" + sessionStorage['advSymbol']+ "&advStartDate="+ sessionStorage['advStartDate']+ "&advType="+sessionStorage["advType"]+ "&advEndDate="+ sessionStorage['advEndDate']+ "&technicals="+sessionStorage['technicals'];;
		
			
		  
		
	  }
	  
function RSIDrawChart(){


	
		//ensure we have all of the required variables
		if(sessionStorage['advStartDate']&&sessionStorage['advEndDate']&&sessionStorage['advSymbol']&&sessionStorage['technicals']&&sessionStorage['advType']){
				  	var technicals =sessionStorage['technicals'].split(",");
			
		for(i=0;i<technicals.length;i++){
			var technicalssplit=technicals[i].split("/");
			console.log(technicalssplit[0]);
			if(technicalssplit[0]=="RSI"){
		document.getElementById("RSI_div").style.display="block";//show the chart div
		
		  // Create and populate the data table.
	  
  var time = <?php echo json_encode($advDates); ?>;
  var RSIData=<?php echo json_encode($RSIarray); ?>;
  console.log("RSI");
  console.log(RSIData);
 

  var data = new google.visualization.DataTable();
  data.addColumn('date', 'days');
  
  	
	
	
		var RSIn=document.getElementById("RSIn");

		data.addColumn('number',"RSI("+RSIn.value+")");	
		

	  
	//for the length of the Symbol data array
		
	console.log("time: "+time.length);	
  for(i = 0; i < time.length; i++){
	  
	  //add row based on count of symbols
	var row=[];
	var index=0;
	var date= time[i].split("-");
	row.push(new Date(date[0], date[1]-1,date[2]));
	
	
	
	row.push(Number(RSIData[0][i]));
	index+=1;
	
	
    data.addRow(row);

	
  }
		}
		var Min=Math.min.apply(Math, RSIData);
		var Max=Math.max.apply(Math, RSIData);
		console.log(Min);
		console.log(Max);
        var options = {
          title: 'Stock RSI for '+sessionStorage['advSymbol'],
          hAxis: {title: 'Day',  titleTextStyle: {color: '#333'}},
          vAxis: {title: 'RSI', minValue: Min},
		  explorer: {axis:'both',
          maxZoomin:0.25,
          keepInBounds: true
    	}
        };
		
        var chart = new google.visualization.AreaChart(document.getElementById('RSI_div'));
        chart.draw(data, options);
	
	
	
}
		}
}

function MacDDrawChart(){
	
		//ensure we have all of the required variables
		if(sessionStorage['advStartDate']&&sessionStorage['advEndDate']&&sessionStorage['advSymbol']&&sessionStorage['technicals']&&sessionStorage['advType']){
				  	var technicals =sessionStorage['technicals'].split(",");
			
		for(i=0;i<technicals.length;i++){
			var technicalssplit=technicals[i].split("/");
			console.log(technicalssplit[0]);
			if(technicalssplit[0]=="MacD"){	
		document.getElementById("MacD_div").style.display="block";//show the chart div
		
		  // Create and populate the data table.
	  
  var time = <?php echo json_encode($advDates); ?>;
  var MacDData=<?php echo json_encode($MacDarray); ?>;
  console.log("MACD");
  console.log(MacDData);
  	var technicals =sessionStorage['technicals'].split(",");
	var MacD="";
	
	for(i=0;i<technicals.length;i++){
		var technicalssplit=technicals[i].split("/");
		console.log(technicalssplit[0]);
		if(technicalssplit[0]=="MacD"){
			MacD=technicals[i];
			
			
		}
	}
	
	MacD=MacD.split("/");
	
	var MacDfastPeriod=MacD[1];
	
	var MacDslowPeriod=MacD[2];
	var MacDsignalPeriod=MacD[3];
	var index= +MacDslowPeriod+ +MacDsignalPeriod-1;
 
	console.log(index);
  var data = new google.visualization.DataTable();
  data.addColumn('date', 'days');
  
  	//add column for the MacD things:
	
	
		data.addColumn('number',"MacD("+MacDfastPeriod+","+MacDslowPeriod+")");	
		data.addColumn('number',"EMA("+MacDsignalPeriod+")");	
		data.addColumn('number',"Divergence");	
		
	//get the technicals info
	

	  
	//for the length of the Symbol data array
		
	console.log("time: "+time.length);	
  for(i = 0; i < time.length; i++){
	  
	  //add row based on count of symbols
	var row=[];
	
	var date= time[i].split("-");
	row.push(new Date(date[0], date[1]-1,date[2]));
	
	
	console.log(+i+ +index);
	row.push(Number(MacDData[0][0][+i+ +index]));
	row.push(Number(MacDData[0][1][+i+ +index]));
	row.push(Number(MacDData[0][2][+i+ +index]));
	

	
	
    data.addRow(row);

	
  }
		}
		var Min=Math.min.apply(Math, MacDData);
		var Max=Math.max.apply(Math, MacDData);
		console.log(Min);
		console.log(Max);
        var options = {
          title: 'Stock MacD for '+sessionStorage['advSymbol'],
          hAxis: {title: 'Day',  titleTextStyle: {color: '#333'}},
          vAxis: {title: 'MacD', minValue: Min},
		  explorer: {axis:'both',
          maxZoomin:0.25,
          keepInBounds: true
    	}
        };
		
        var chart = new google.visualization.AreaChart(document.getElementById('MacD_div'));
        chart.draw(data, options);
	
	
	
}
		}
}

function ROCDrawChart(){
	
		//ensure we have all of the required variables
		if(sessionStorage['advStartDate']&&sessionStorage['advEndDate']&&sessionStorage['advSymbol']&&sessionStorage['technicals']&&sessionStorage['advType']){
				  	var technicals =sessionStorage['technicals'].split(",");
			
		for(i=0;i<technicals.length;i++){
			var technicalssplit=technicals[i].split("/");
			console.log(technicalssplit[0]);
			if(technicalssplit[0]=="ROC"){
		document.getElementById("ROC_div").style.display="block";//show the chart div
		
		  // Create and populate the data table.
	  
  var time = <?php echo json_encode($advDates); ?>;
  var ROCData=<?php echo json_encode($ROCarray); ?>;


  var data = new google.visualization.DataTable();
  data.addColumn('date', 'days');
  
  	
	
	
		var RSIn=document.getElementById("ROCn");

		data.addColumn('number',"ROC("+ROCn.value+")");	
		

	  
	//for the length of the Symbol data array
		
	console.log("time: "+time.length);	
  for(i = 0; i < time.length; i++){
	  
	  //add row based on count of symbols
	var row=[];
	var index=0;
	var date= time[i].split("-");
	row.push(new Date(date[0], date[1]-1,date[2]));
	
	
	
	row.push(Number(ROCData[0][i]));
	index+=1;
	
	
    data.addRow(row);

	
  }
		}
		var Min=Math.min.apply(Math, ROCData);
		var Max=Math.max.apply(Math, ROCData);
		console.log(Min);
		console.log(Max);
        var options = {
          title: 'Stock ROC for '+sessionStorage['advSymbol'],
          hAxis: {title: 'Day',  titleTextStyle: {color: '#333'}},
          vAxis: {title: 'ROC', minValue: Min},
		  explorer: {axis:'both',
          maxZoomin:0.25,
          keepInBounds: true
    	}
        };
		
        var chart = new google.visualization.AreaChart(document.getElementById('ROC_div'));
        chart.draw(data, options);
	
	
	
}
		}
}
function OBVDrawChart(){


	
		//ensure we have all of the required variables
		if(sessionStorage['advStartDate']&&sessionStorage['advEndDate']&&sessionStorage['advSymbol']&&sessionStorage['technicals']&&sessionStorage['advType']){
				  	var technicals =sessionStorage['technicals'].split(",");
			
		for(i=0;i<technicals.length;i++){
			var technicalssplit=technicals[i].split("/");
			console.log(technicalssplit[0]);
			if(technicalssplit[0]=="OBV"){
		document.getElementById("OBV_div").style.display="block";//show the chart div
		
		  // Create and populate the data table.
	  
  var time = <?php echo json_encode($advDates); ?>;
  var OBVData=<?php echo json_encode($OBVarray); ?>;


  var data = new google.visualization.DataTable();
  data.addColumn('date', 'days');
  
  	
	
	
		var OBVn=document.getElementById("OBVn");

		data.addColumn('number',"OBV("+OBVn.value+")");	
		

	  
	//for the length of the Symbol data array
		
	console.log("time: "+time.length);	
  for(i = 0; i < time.length; i++){
	  
	  //add row based on count of symbols
	var row=[];
	var index=0;
	var date= time[i].split("-");
	row.push(new Date(date[0], date[1]-1,date[2]));
	
	
	
	row.push(Number(OBVData[0][i]));
	index+=1;
	
	
    data.addRow(row);

	
  }
		}
		var Min=Math.min.apply(Math, OBVData);
		var Max=Math.max.apply(Math, OBVData);
		console.log(Min);
		console.log(Max);
        var options = {
          title: 'Stock OBV for '+sessionStorage['advSymbol'],
          hAxis: {title: 'Day',  titleTextStyle: {color: '#333'}},
          vAxis: {title: 'OBV', minValue: Min},
		  explorer: {axis:'both',
          maxZoomin:0.25,
          keepInBounds: true
    	}
        };
		
        var chart = new google.visualization.AreaChart(document.getElementById('OBV_div'));
        chart.draw(data, options);
	
	
	
}
		}
}
function WilliamRDrawChart(){

		//ensure we have all of the required variables
		if(sessionStorage['advStartDate']&&sessionStorage['advEndDate']&&sessionStorage['advSymbol']&&sessionStorage['technicals']&&sessionStorage['advType']){
				  	var technicals =sessionStorage['technicals'].split(",");
			
		for(i=0;i<technicals.length;i++){
			var technicalssplit=technicals[i].split("/");
			console.log(technicalssplit[0]);
			if(technicalssplit[0]=="WilliamR"){
		document.getElementById("WilliamR_div").style.display="block";//show the chart div
		
		  // Create and populate the data table.
	  
  var time = <?php echo json_encode($advDates); ?>;
  var WilliamRData=<?php echo json_encode($WilliamRarray); ?>;


  var data = new google.visualization.DataTable();
  data.addColumn('date', 'days');
  
  	
	
	
		var WilliamRn=document.getElementById("WilliamRn");

		data.addColumn('number',"WilliamR("+WilliamRn.value+")");	
		

	  
	//for the length of the Symbol data array
		
	console.log("time: "+time.length);	
  for(i = 0; i < time.length; i++){
	  
	  //add row based on count of symbols
	var row=[];
	var index=0;
	var date= time[i].split("-");
	row.push(new Date(date[0], date[1]-1,date[2]));
	
	
	
	row.push(Number(WilliamRData[0][i]));
	index+=1;
	
	
    data.addRow(row);

	
  }
		}
		var Min=Math.min.apply(Math, WilliamRData);
		var Max=Math.max.apply(Math, WilliamRData);
		console.log(Min);
		console.log(Max);
        var options = {
          title: 'Stock WilliamR for '+sessionStorage['advSymbol'],
          hAxis: {title: 'Day',  titleTextStyle: {color: '#333'}},
          vAxis: {title: 'WilliamR', minValue: Min},
		  explorer: {axis:'both',
          maxZoomin:0.25,
          keepInBounds: true
    	}
        };
		
        var chart = new google.visualization.AreaChart(document.getElementById('WilliamR_div'));
        chart.draw(data, options);
	
	
	
}
		}
}

function MTMDrawChart(){


	
		//ensure we have all of the required variables
		if(sessionStorage['advStartDate']&&sessionStorage['advEndDate']&&sessionStorage['advSymbol']&&sessionStorage['technicals']&&sessionStorage['advType']){
				  	var technicals =sessionStorage['technicals'].split(",");
			
		for(i=0;i<technicals.length;i++){
			var technicalssplit=technicals[i].split("/");
			console.log(technicalssplit[0]);
			if(technicalssplit[0]=="MTM"){
		document.getElementById("MTM_div").style.display="block";//show the chart div
		
		  // Create and populate the data table.
	  
  var time = <?php echo json_encode($advDates); ?>;
  var MTMData=<?php echo json_encode($MTMarray); ?>;


  var data = new google.visualization.DataTable();
  data.addColumn('date', 'days');
  
  	
	
	
		var MTMn=document.getElementById("MTMn");

		data.addColumn('number',"MTM("+MTMn.value+")");	
		

	  
	//for the length of the Symbol data array
		
	console.log("time: "+time.length);	
  for(i = 0; i < time.length; i++){
	  
	  //add row based on count of symbols
	var row=[];
	var index=0;
	var date= time[i].split("-");
	row.push(new Date(date[0], date[1]-1,date[2]));
	
	
	
	row.push(Number(MTMData[0][i]));
	index+=1;
	
	
    data.addRow(row);

	
  }
		}
		var Min=Math.min.apply(Math, MTMData);
		var Max=Math.max.apply(Math, MTMData);
		console.log(Min);
		console.log(Max);
        var options = {
          title: 'Stock MTM for '+sessionStorage['advSymbol'],
          hAxis: {title: 'Day',  titleTextStyle: {color: '#333'}},
          vAxis: {title: 'MTM', minValue: Min},
		  explorer: {axis:'both',
          maxZoomin:0.25,
          keepInBounds: true
    	}
        };
		
        var chart = new google.visualization.AreaChart(document.getElementById('MTM_div'));
        chart.draw(data, options);
	
	
	
}
		}
}

function FastSTCDrawChart(){


	
		//ensure we have all of the required variables
		if(sessionStorage['advStartDate']&&sessionStorage['advEndDate']&&sessionStorage['advSymbol']&&sessionStorage['technicals']&&sessionStorage['advType']){
				  	var technicals =sessionStorage['technicals'].split(",");
			
		for(i=0;i<technicals.length;i++){
			var technicalssplit=technicals[i].split("/");
			console.log(technicalssplit[0]);
			if(technicalssplit[0]=="FastSTC"){
		document.getElementById("FastSTC_div").style.display="block";//show the chart div
		
		  // Create and populate the data table.
	  
  var time = <?php echo json_encode($advDates); ?>;
  var FastSTCData=<?php echo json_encode($FastSTCarray); ?>;
  console.log("FastSTC");
  console.log(FastSTCData);
	var technicals =sessionStorage['technicals'].split(",");
	var FastSTC="";
	
	for(i=0;i<technicals.length;i++){
		var technicalssplit=technicals[i].split("/");
		console.log(technicalssplit[0]);
		if(technicalssplit[0]=="FastSTC"){
			FastSTC=technicals[i];
			
			
		}
	}
	
	FastSTC=FastSTC.split("/");
	
	var fastK=FastSTC[1];
	var fastD=FastSTC[2];

	var index= +fastK+ +fastD-1;

  var data = new google.visualization.DataTable();
  data.addColumn('date', 'days');
  
  	
	
	
		var FastSTCn=document.getElementById("FastSTCn");

		data.addColumn('number',"Fstc("+FastSTCn.value+")%K");	
		data.addColumn('number',"Fstc("+FastSTCn.value+")%D");
		

	  
	//for the length of the Symbol data array
		
	console.log("time: "+time.length);	
  for(i = 0; i < time.length; i++){
	  
	  //add row based on count of symbols
	var row=[];
	
	var date= time[i].split("-");
	row.push(new Date(date[0], date[1]-1,date[2]));
	
	
	
	row.push(Number(FastSTCData[0][0][+i+ +index]));
	row.push(Number(FastSTCData[0][1][+i+ +index]));
	
	
	
    data.addRow(row);

	
  }
		}
		var Min=Math.min.apply(Math, FastSTCData);
		var Max=Math.max.apply(Math, FastSTCData);
		console.log(Min);
		console.log(Max);
        var options = {
          title: 'Stock FastSTC for '+sessionStorage['advSymbol'],
          hAxis: {title: 'Day',  titleTextStyle: {color: '#333'}},
          vAxis: {title: 'FastSTC', minValue: Min},
		  explorer: {axis:'both',
          maxZoomin:0.25,
          keepInBounds: true
    	}
        };
		
        var chart = new google.visualization.AreaChart(document.getElementById('FastSTC_div'));
        chart.draw(data, options);
	
	
	
}
		}
}

function DMIDrawChart(){


	
		//ensure we have all of the required variables
		if(sessionStorage['advStartDate']&&sessionStorage['advEndDate']&&sessionStorage['advSymbol']&&sessionStorage['technicals']&&sessionStorage['advType']){
			var technicals =sessionStorage['technicals'].split(",");
				
			for(i=0;i<technicals.length;i++){
				var technicalssplit=technicals[i].split("/");
				console.log(technicalssplit[0]);
				if(technicalssplit[0]=="DMI"){
			document.getElementById("DMI_div").style.display="block";//show the chart div
		
		  // Create and populate the data table.
	  
  var time = <?php echo json_encode($advDates); ?>;
  var DMIData=<?php echo json_encode($DMIarray); ?>;
  console.log("DMI");
  console.log(DMIData);

	


  var data = new google.visualization.DataTable();
  data.addColumn('date', 'days');
  
  	
	
	
		var DMIn=document.getElementById("DMIn");

		data.addColumn('number',"+dmi("+DMIn.value+")");	
		data.addColumn('number',"-dmi("+DMIn.value+")");
		

	  
	//for the length of the Symbol data array
		
	console.log("time: "+time.length);	
  for(i = 0; i < time.length; i++){
	  
	  //add row based on count of symbols
	var row=[];
	
	var date= time[i].split("-");
	row.push(new Date(date[0], date[1]-1,date[2]));
	
	
	
	row.push(Number(DMIData[1][i+ +DMIn.value]));
	row.push(Number(DMIData[0][i+ +DMIn.value]));
	
	
	
    data.addRow(row);

	
  }
		}
		var Min=Math.min.apply(Math, DMIData);
		var Max=Math.max.apply(Math, DMIData);
		console.log(Min);
		console.log(Max);
        var options = {
          title: 'Stock DMI for '+sessionStorage['advSymbol'],
          hAxis: {title: 'Day',  titleTextStyle: {color: '#333'}},
          vAxis: {title: 'DMI', minValue: Min},
		  explorer: {axis:'both',
          maxZoomin:0.25,
          keepInBounds: true
    	}
        };
		
        var chart = new google.visualization.AreaChart(document.getElementById('DMI_div'));
        chart.draw(data, options);
	
	
	
}
		}
}

function PVTDrawChart(){


	
		//ensure we have all of the required variables
		if(sessionStorage['advStartDate']&&sessionStorage['advEndDate']&&sessionStorage['advSymbol']&&sessionStorage['technicals']&&sessionStorage['advType']){
				  	var technicals =sessionStorage['technicals'].split(",");
			
		for(i=0;i<technicals.length;i++){
			var technicalssplit=technicals[i].split("/");
			console.log(technicalssplit[0]);
			if(technicalssplit[0]=="PVT"){
		document.getElementById("PVT_div").style.display="block";//show the chart div
		
		  // Create and populate the data table.
	  
  var time = <?php echo json_encode($advDates); ?>;
  var PVTData=<?php echo json_encode($PVTarray); ?>;
  console.log("PVTss");
  console.log(PVTData);


  var data = new google.visualization.DataTable();
  data.addColumn('date', 'days');
  
  	
	
	
		var PVTn=document.getElementById("PVTn");

		data.addColumn('number',"PVT");	
		

	  
	//for the length of the Symbol data array
		
	console.log("time: "+time.length);	
  for(i = 0; i < time.length; i++){
	  
	  //add row based on count of symbols
	var row=[];
	var index=0;
	var date= time[i].split("-");
	row.push(new Date(date[0], date[1]-1,date[2]));
	
	
	
	row.push(Number(PVTData[i]));
	index+=1;
	
	
    data.addRow(row);

	
  }
		}
		var Min=Math.min.apply(Math, PVTData);
		var Max=Math.max.apply(Math, PVTData);
		console.log(Min);
		console.log(Max);
        var options = {
          title: 'Stock PVT for '+sessionStorage['advSymbol'],
          hAxis: {title: 'Day',  titleTextStyle: {color: '#333'}},
          vAxis: {title: 'PVT', minValue: Min},
		  explorer: {axis:'both',
          maxZoomin:0.25,
          keepInBounds: true
    	}
        };
		
        var chart = new google.visualization.AreaChart(document.getElementById('PVT_div'));
        chart.draw(data, options);
	
	
	
}
		}
}
	  
function ProcessAnalysis(){
	var RSI=document.getElementById('RSI');
	var MacD=document.getElementById('MacD');
	var ROC=document.getElementById('ROC');
	var OBV=document.getElementById('OBV');
	var WilliamR=document.getElementById('WilliamR');
	var MTM=document.getElementById('MTM');
	var SlowSTC=document.getElementById('SlowSTC');
	var FastSTC=document.getElementById('FastSTC');
	var DMI=document.getElementById('DMI');
	var PVT=document.getElementById('PVT');
	
	var RSIn=document.getElementById('RSIn');
	var MacDn=document.getElementById('MacDn');
	var ROCn=document.getElementById('ROCn');
	var OBVn=document.getElementById('OBVn');
	var WilliamRn=document.getElementById('WilliamRn');
	var MTMn=document.getElementById('MTMn');
	var SlowSTCn=document.getElementById('SlowSTCn');
	var FastSTCn=document.getElementById('FastSTCn');
	var DMIn=document.getElementById('DMIn');
	var PVTn=document.getElementById('PVTn');
	
	//Create an array of checked boxes to be displayed.
			var technicals =[];
			
			//check if displays array is already in local cache
			
			if(sessionStorage['technicals']){
				//add local storage displays to the displays array
				var localtechnicals=sessionStorage['technicals'].split(",");
				for(i=0;i<localtechnicals.length;i++){
					technicals.push(localtechnicals[i]);	
				
				}
			}
			
			
			if(RSI.checked==true){
				//ensure that their is only one SMA in the dispalys array
				for(var i=0;i<technicals.length;i++){
					var technicalcheck = technicals[i].split("/");
					if(technicalcheck[0]=="RSI"){
						technicals.splice(i,1);		
					}
				}

					if(RSIn.value==""){
						technicals.push("RSI/14");
					}else{
						technicals.push("RSI/"+RSIn.value);
					}	
			}else{
				if(technicals.indexOf("RSI/"+RSIn.value)>-1){
					technicals.splice(technicals.indexOf("RSI/"+RSIn.value), 1);//remove from displays array
				}
				
					
			}
			
			if(MacD.checked==true){
				//ensure that their is only one SMA in the dispalys array
				for(var i=0;i<technicals.length;i++){
					var technicalcheck = technicals[i].split("/");
					if(technicalcheck[0]=="MacD"){
						technicals.splice(i,1);		
					}
				}

					if(MacDn.value==""){
						technicals.push("MacD/12/26/9");
					}else{
						technicals.push("MacD/"+MacDn.value);
					}	
			}else{
				if(technicals.indexOf("MacD/"+MacDn.value)>-1){
					technicals.splice(technicals.indexOf("MacD/"+MacDn.value), 1);//remove from displays array
				}
				
					
			}

			if(ROC.checked==true){
				//ensure that their is only one SMA in the dispalys array
				for(var i=0;i<technicals.length;i++){
					var technicalcheck = technicals[i].split("/");
					if(technicalcheck[0]=="ROC"){
						technicals.splice(i,1);		
					}
				}

					if(ROCn.value==""){
						technicals.push("ROC/12");
					}else{
						technicals.push("ROC/"+ROCn.value);
					}	
			}else{
				if(technicals.indexOf("ROC/"+ROCn.value)>-1){
					technicals.splice(technicals.indexOf("ROC/"+ROCn.value), 1);//remove from displays array
				}
				
					
			}
			
			if(OBV.checked==true){
				//ensure that their is only one SMA in the dispalys array
				for(var i=0;i<technicals.length;i++){
					var technicalcheck = technicals[i].split("/");
					if(technicalcheck[0]=="OBV"){
						technicals.splice(i,1);		
					}
				}

					if(OBVn.value==""){
						technicals.push("OBV/none");
					}else{
						technicals.push("OBV/"+OBVn.value);
					}	
			}else{
				if(technicals.indexOf("OBV/"+OBVn.value)>-1){
					technicals.splice(technicals.indexOf("OBV/"+OBVn.value), 1);//remove from displays array
				}
				
					
			}
			
			if(WilliamR.checked==true){
				//ensure that their is only one SMA in the dispalys array
				for(var i=0;i<technicals.length;i++){
					var technicalcheck = technicals[i].split("/");
					if(technicalcheck[0]=="WilliamR"){
						technicals.splice(i,1);		
					}
				}

					if(WilliamRn.value==""){
						technicals.push("WilliamR/14");
					}else{
						technicals.push("WilliamR/"+WilliamRn.value);
					}	
			}else{
				if(technicals.indexOf("WilliamR/"+WilliamRn.value)>-1){
					technicals.splice(technicals.indexOf("WilliamR/"+WilliamRn.value), 1);//remove from displays array
				}
				
					
			}
			
			if(MTM.checked==true){
				//ensure that their is only one SMA in the dispalys array
				for(var i=0;i<technicals.length;i++){
					var technicalcheck = technicals[i].split("/");
					if(technicalcheck[0]=="MTM"){
						technicals.splice(i,1);		
					}
				}

					if(MTMn.value==""){
						technicals.push("MTM/9");
					}else{
						technicals.push("MTM/"+MTMn.value);
					}	
			}else{
				if(technicals.indexOf("MTM/"+MTMn.value)>-1){
					technicals.splice(technicals.indexOf("MTM/"+MTMn.value), 1);//remove from displays array
				}
				
					
			}
			
			if(SlowSTC.checked==true){
				//ensure that their is only one SMA in the dispalys array
				for(var i=0;i<technicals.length;i++){
					var technicalcheck = technicals[i].split("/");
					if(technicalcheck[0]=="SlowSTC"){
						technicals.splice(i,1);		
					}
				}

					if(SlowSTCn.value==""){
						technicals.push("SlowSTC/20/5");
					}else{
						technicals.push("SlowSTC/"+SlowSTCn.value);
					}	
			}else{
				if(technicals.indexOf("SlowSTC/"+SlowSTCn.value)>-1){
					technicals.splice(technicals.indexOf("SlowSTC/"+SlowSTCn.value), 1);//remove from displays array
				}
				
					
			}
			
			if(FastSTC.checked==true){
				//ensure that their is only one SMA in the dispalys array
				for(var i=0;i<technicals.length;i++){
					var technicalcheck = technicals[i].split("/");
					if(technicalcheck[0]=="FastSTC"){
						technicals.splice(i,1);		
					}
				}

					if(FastSTCn.value==""){
						technicals.push("FastSTC/20/5");
					}else{
						technicals.push("FastSTC/"+FastSTCn.value);
					}	
			}else{
				if(technicals.indexOf("FastSTC/"+FastSTCn.value)>-1){
					technicals.splice(technicals.indexOf("FastSTC/"+FastSTCn.value), 1);//remove from displays array
				}
				
					
			}
			
			if(DMI.checked==true){
				//ensure that their is only one SMA in the dispalys array
				for(var i=0;i<technicals.length;i++){
					var technicalcheck = technicals[i].split("/");
					if(technicalcheck[0]=="DMI"){
						technicals.splice(i,1);		
					}
				}

					if(DMIn.value==""){
						technicals.push("DMI/14");
					}else{
						technicals.push("DMI/"+DMIn.value);
					}	
			}else{
				if(technicals.indexOf("DMI/"+DMIn.value)>-1){
					technicals.splice(technicals.indexOf("DMI/"+DMIn.value), 1);//remove from displays array
				}
				
					
			}
			
			if(PVT.checked==true){
				//ensure that their is only one SMA in the dispalys array
				for(var i=0;i<technicals.length;i++){
					var technicalcheck = technicals[i].split("/");
					if(technicalcheck[0]=="PVT"){
						technicals.splice(i,1);		
					}
				}

					if(PVTn.value==""){
						technicals.push("PVT/14");
					}else{
						technicals.push("PVT/"+PVTn.value);
					}	
			}else{
				if(technicals.indexOf("PVT/"+PVTn.value)>-1){
					technicals.splice(technicals.indexOf("PVT/"+PVTn.value), 1);//remove from displays array			}
				
					
			}

			}
			
			
			
			
			
		//remove duplicates if any
		technicals = technicals.filter(function(elem, pos, self) {
		return self.indexOf(elem) == pos;
		});
				
			
			
			
		//Add Array of displays to local storage
		window.sessionStorage.setItem("technicals", technicals);
		window.location.href = "chartIndicators.php?displays=" +sessionStorage['displays']+ "&advSymbol=" + sessionStorage['advSymbol']+ "&advStartDate="+ sessionStorage['advStartDate']+ "&advType="+sessionStorage["advType"]+ "&advEndDate="+ sessionStorage['advEndDate']+ "&technicals="+sessionStorage['technicals'];;
		
	
	
}

function showInfo(sender){
	var show=document.getElementById("info_div")
	if( show.style.display=="none"){
		show.style.display="block"	
	}else{
		show.style.display="none";	
	}
	var info= document.getElementById("infoText");
	var textExample= document.getElementById("exampleText");
	

	switch(sender){
		case "SMA":
			info.innerHTML="<strong>Description:</strong> Moving averages smooth the price data to form a trend following indicator. A simple moving average is formed by computing the average price of a security over a specific number of periods. Old data is dropped as new data comes available. This causes the average to move along the time scale.";
			textExample.innerHTML="<strong>How to:</strong> Calculate the SMA by filling in the provided text box like: '20/50/100'. Where the '/' adds another line to be plotted."
			break;
			
		case "EMA":
			info.innerHTML="<strong>Description:</strong> Exponential moving average is a type of moving average that is similar to a simple moving average, except that more weight is given to the latest data. The weighting for each older data point decreases exponentially, never reaching zero. It reduces the lag by applying more weight to recent prices.";
			textExample.innerHTML="<strong>How to:</strong> Calculate the EMA by filling in the provided text box like: '20/50/100'. Where the '/' adds another line to be plotted."
			break;
			
		case "WMA":
			info.innerHTML="<strong>Description:</strong> The Weighted Moving Average (WMA) finds the average price of a security over a set number of periods. It gives more weight to the more recent prices, relative to older prices, in an attempt to reduce the lag associated with moving averages, in general. This is calculated by multiplying each of the previous interval's data by a weight based on the period length in the WMA. Each price is multiplied by a factor, with the current price having the highest factor and each price after that having a factor of the prior price less one.";
			textExample.innerHTML="<strong>How to:</strong> Calculate the WMA by filling in the provided text box like: '20/50/100'. Where the '/' adds another line to be plotted."
			break;
			
		case "SAR":
			info.innerHTML="<strong>Description:</strong> SAR stands for 'stop and reverse', which is the actual indicator used in the system. SAR trails price as the trend extends over time. The indicator is below prices when prices are rising and above prices when prices are falling. In this regard, the indicator stops and reverses when the price trend reverses and breaks above or below the indicator.";
			textExample.innerHTML="<strong>How to:</strong> Calculate the SAR by filling in the provided text box like: 'x/y', Where the 'x' is the acceleration factor and 'y' is the Maximum."
			break;
			
		case "Bollinger":
			info.innerHTML="<strong>Description:</strong> Bollinger Bands are volatility bands placed above and below a moving average. The Bollinger Band includes 3 lines: the upper band, lower band, and the centerline. The centerline is simply the moving average, and the upper and lower bands are, respectively, the center line plus/minus twice the standard deviation. ";
			textExample.innerHTML="<strong>How to:</strong> Calculate the Bollinger bands by filling in the provided text box like: 'x/y', Where the 'x' is the SMA days and 'y' is the standard deviation."
			break;
			
			case "RSI":
			info.innerHTML="<strong>Description:</strong> A technical momentum indicator that compares the magnitude of recent gains to recent losses in an attempt to determine overbought and oversold conditions of an asset.";
			textExample.innerHTML="<strong>How to:</strong> Calculate the RSI bands by filling in the provided text box like: 'x/y', Where the 'x' is the SMA days and 'y' is the standard deviation."
			break;
			
			case "MacD":
			info.innerHTML="<strong>Description:</strong> A trend-following momentum indicator that shows the relationship between two moving averages of prices. The MACD is calculated by subtracting the 26-day exponential moving average (EMA) from the 12-day EMA. A nine-day EMA of the MACD, called the 'signal line', is then plotted on top of the MACD, functioning as a trigger for buy and sell signals.";
			textExample.innerHTML="<strong>How to:</strong> Calculate the MacD by filling in the provided text box like: 'x/y/z', Where the 'x' is the Shorter EMA and 'y' is the Longer EMA and z is the Signal line-EMA of MACD."
			break;
				
			case "ROC":
			info.innerHTML="<strong>Description:</strong> It measures the percentage change in price over a given period of time. As a momentum oscillator, ROC signals include centerline crossovers, divergences and overbought-oversold readings.";
			textExample.innerHTML="<strong>How to:</strong> Calculate the ROC by filling in the provided text box like: 'x', Where the 'x' is the number of periods."
			break;
			
			case "OBV":
			info.innerHTML="<strong>Description:</strong> OBV is calculated by adding the day's volume to a running cumulative total when the security's price closes up, and subtracts the volume when it closes down. An OBV provides a running total of volume and shows whether this volume is flowing in or out of a given security. This line can then be compared with the price chart of the underlying security to look for divergences or confirmation.";
			textExample.innerHTML="<strong>How to:</strong> OBV does NOT require any input."
			break;
			
			case "WilliamR":
			info.innerHTML="<strong>Description:</strong> It measures whether or not a security is overbought or oversold. The indicator is designed to show the relationship between the period high and the current close within the specified period. The scale ranges from 0 to -100 with readings from 0 to -20 considered overbought, and readings from -80 to -100 considered oversold.";
			textExample.innerHTML="<strong>How to:</strong> Calculate the William%R by filling in the provided text box like: 'x', Where the 'x' is the number of periods."
			break;
						
			case "MTM":
			info.innerHTML="<strong>Description:</strong> Momentum is an oscillator-type indicator used to detect overbought and oversold conditions and to perform as a gauge indicating the strength of the current trend. When momentum is above the zero-line and rising, prices are increasing at an increasing rate. If momentum is above the zero line but is declining, prices are still increasing but at a decreasing rate. On the other hand, when momentum is below the zero-line and falling, prices are decreasing at an increasing rate. If momentum is below the zero line but is rising, prices are still declining but at a decreasing rate.";
			textExample.innerHTML="<strong>How to:</strong> Calculate the MTM by filling in the provided text box like: 'x', Where the 'x' is the number of periods."
			break;
									
			case "SlowSTC":
			info.innerHTML="<strong>Description: !~NOT WORKING~!</strong> The slow stochastic oscillator compares two lines called the %K and %D lines to predict the possibility of an uptrend or a downtrend. The Stochastic Oscillator averages lowest lows and highest highs of the stock on a fixed period of time in the process of calculation. This results in a smoother behavior of this indicator comparing to Fast Stochastic Oscillator.";
			textExample.innerHTML="<strong>How to:</strong> Calculate the SlowSTC by filling in the provided text box like: '%K/%D'."
			break;
												
			case "FastSTC":
			info.innerHTML="<strong>Description:</strong> The fast stochastic oscillator compares two lines called the %K and %D lines to predict the possibility of an uptrend or a downtrend he fast stochastic oscillator compares two lines called the %K and %D lines to predict the possibility of an uptrend or a downtrend. ";
			textExample.innerHTML="<strong>How to:</strong> Calculate the William%R bands by filling in the provided text box like: '%K/%D'."
			break;
															
			case "DMI":
			info.innerHTML="<strong>Description:</strong> An indicator that plots a positive +DI line measuring buying pressure and a negative -DI line measuring selling pressure. The DMI pattern is bullish as long as the +DI line is above the -DI line. The Average Directional Index line is derived from this system and is based on the spread between the +DI and -DI lines. ";
			textExample.innerHTML="<strong>How to:</strong> Calculate the DMI by filling in the provided text box like: 'x', Where x is the number of periods"
			break;
																		
			case "PVT":
			info.innerHTML="<strong>Description:</strong> It represents the growing sum of values of the trade volume calculated regarding the change of closing prices. It adds a small part of the volume to the current cumulate value if the relative change of price is not big. If the price changed considerably, a large part of the volume is added to the PVT value. ";
			textExample.innerHTML="<strong>How to:</strong> PVT does NOT require any input."
			break;
			
	}
	
}

    </script>
  
  				
              <h4>Compare Stock indicators with only one symbol.</h4>
              
              <label for="textfield2">Add Symbol:</label>
              <select id='advSymbol' name='advSymbol' onChange="addSymbol()">
              <option value='none'>Choose symbol</option>
              <?php
				$result = mysqli_query($con,"SELECT * FROM  `company info`");


				

				while($row = mysqli_fetch_array($result)) {
					
    				echo "<option value='$row[Symbol]'>" . $row['Symbol'] . "</option>";

				}
				
				echo "</select>";
				//mysqli_close($con);
			  
			  //generate a button for each symbol to remove 	

			  ?>
              <label>Start date</label>
              <input type="date" id="advStartDate" onChange="processAdvDate()">
              <label>End date</label>
              <input type="date" id="advEndDate" onChange="processAdvDate()">
              <label>Type</label>
              <select id='advType' name='advType' onChange="advProcessType()">
              <option value='none'>Choose type</option>
              <option value='Close'>Close</option>
              <option value='High'>High</option>
              <option value='Low'>Low</option>
              <option value='Open'>Open</option>
              </select>
              
              <br>
              <label>Display:</label>
              <input type="checkbox"  name="SMA" id="SMA" value="SMA" onChange="ProcessDisplay()">SMA<input type="button" class="inf" id="SMAi" value="info" onClick="showInfo('SMA')">             								 			  <input type="text" name="SMAn" id="SMAn" value="" size="4" onChange="ProcessDisplay()">
              <input type="checkbox" name="WMA" id="WMA" value="WMA" onChange="ProcessDisplay()">WMA<input type="button" class="inf" id="WMAi" value="info" onClick="showInfo('WMA')">  
              <input type="text" name="WMAn" id="WMAn" value="" size="4" onChange="ProcessDisplay()">
              <input type="checkbox" name="EMA" id="EMA" value="EMA" onChange="ProcessDisplay()">EMA<input type="button" class="inf" id="EMAi" value="info" onClick="showInfo('EMA')"> 
              <input type="text" name="EMAn" id="EMAn" value="" size="4" onChange="ProcessDisplay()">
              <input type="checkbox" name="SAR" id="SAR" value="SAR" onChange="ProcessDisplay()">SAR<input type="button" class="inf" id="SARi" value="info" onClick="showInfo('SAR')"> 
              <input type="text" name="SARn" id="SARn" value="" size="4" onChange="ProcessDisplay()">
              <input type="checkbox" name="Bollinger" id="Bollinger" value="Bollinger" onChange="ProcessDisplay()">Bollinger<input type="button" class="inf" id="Bollingeri" value="info" onClick="showInfo('Bollinger')"> 
              <input type="text" name="Bollingern" id="Bollingern" value="" size="4" onChange="ProcessDisplay()">
                 
	<br>
			 <label>Technical Analysis:</label>
             <input type="checkbox"  name="RSI" id="RSI" value="RSI" onChange="ProcessAnalysis()">RSI<input type="button" class="inf" id="RSIi" value="info" onClick="showInfo('RSI')">      
             <input type="text" name="RSIn" id="RSIn" value="" size="4" onChange="ProcessAnalysis()">   
             <input type="checkbox"  name="MacD" id="MacD" value="MacD" onChange="ProcessAnalysis()">MacD<input type="button" class="inf" id="MacDi" value="info" onClick="showInfo('MacD')">
             <input type="text" name="MacDn" id="MacDn" value="" size="4" onChange="ProcessAnalysis()">   
             <input type="checkbox"  name="ROC" id="ROC" value="ROC" onChange="ProcessAnalysis()">ROC<input type="button" class="inf" id="ROCi" value="info" onClick="showInfo('ROC')">
             <input type="text" name="ROCn" id="ROCn" value="" size="4" onChange="ProcessAnalysis()">   
             <input type="checkbox"  name="OBV" id="OBV" value="OBV" onChange="ProcessAnalysis()">OBV<input type="button" class="inf" id="OBVi" value="info" onClick="showInfo('OBV')">
             <input type="text" name="OBVn" id="OBVn" value="" size="4" onChange="ProcessAnalysis()">   
             <input type="checkbox"  name="WilliamR" id="WilliamR" value="WilliamR" onChange="ProcessAnalysis()">WilliamR<input type="button" class="inf" id="WilliamRi" value="info" onClick="showInfo('WilliamR')">
             <input type="text" name="WilliamRn" id="WilliamRn" value="" size="4" onChange="ProcessAnalysis()">   
              <input type="checkbox"  name="MTM" id="MTM" value="MTM" onChange="ProcessAnalysis()">MTM<input type="button" class="inf" id="MTMi" value="info" onClick="showInfo('MTM')">
              <input type="text" name="MTMn" id="MTMn" value="" size="4" onChange="ProcessAnalysis()">   
              <input type="checkbox"  name="SlowSTC" id="SlowSTC" value="SlowSTC" onChange="ProcessAnalysis()">SlowSTC<input type="button" class="inf" id="SlowSTCi" value="info" onClick="showInfo('SlowSTC')">
              <input type="text" name="SlowSTCn" id="SlowSTCn" value="" size="4" onChange="ProcessAnalysis()">
                 
    <input type="checkbox"  name="FastSTC" id="FastSTC" value="FastSTC" onChange="ProcessAnalysis()">FastSTC<input type="button" class="inf" id="FastSTCi" value="info" onClick="showInfo('FasrSTC')">
              <input type="text" name="FastSTCn" id="FastSTCn" value="" size="4" onChange="ProcessAnalysis()">   
              <input type="checkbox"  name="DMI" id="DMI" value="DMI" onChange="ProcessAnalysis()">DMI<input type="button" class="inf" id="DMIi" value="info" onClick="showInfo('DMI')">
              <input type="text" name="DMIn" id="DMIn" value="" size="4" onChange="ProcessAnalysis()">   
              <input type="checkbox"  name="PVT" id="PVT" value="PVT" onChange="ProcessAnalysis()">PVT<input type="button" class="inf" id="PVTi" value="info" onClick="showInfo('PVT')">
              <input type="text" name="PVTn" id="PVTn" value="" size="4" onChange="ProcessAnalysis()">   
              </form>

  
              <div id="info_div" style="width: 900px; height: 120px; background-color:#CCC; display:none;">
             <label id="infoText" value="YOLO"></label>
             <label id="exampleText" value="YOLO"></label></div>
            <div id="indicatorChart_div" style="width: 1000px; height: 400px; display:none;"></div>
            <div id="RSI_div" style="width: 950px; height: 300px; display:none;"></div>
            <div id="MacD_div" style="width: 950px; height: 300px; display:none;"></div>
            <div id="ROC_div" style="width: 950px; height: 300px; display:none;"></div>
            <div id="OBV_div" style="width: 950px; height: 300px; display:none;"></div>
            <div id="WilliamR_div" style="width: 950px; height: 300px; display:none;"></div>
            <div id="MTM_div" style="width: 950px; height: 300px; display:none;"></div>
            <div id="SlowSTC_div" style="width: 950px; height: 300px; display:none;"></div>
            <div id="FastSTC_div" style="width: 950px; height: 300px; display:none;"></div>
            <div id="DMI_div" style="width: 950px; height: 300px; display:none;"></div>
            <div id="PVT_div" style="width: 950px; height: 300px; display:none;"></div>

            
            
            
            
    <script type="text/javascript">

		//display all the things!	
		if(sessionStorage['displays']){
		  
				//set localdisplays now so we can use it again
					
			var localdisplays=sessionStorage['displays'].split(",");
				for(i=0;i<localdisplays.length;i++){
					var splitdisplay=localdisplays[i].split("/");
					if(splitdisplay.length>2){
						var type=splitdisplay[0];
						splitdisplay.splice(0,1);
					document.getElementById(type).setAttribute("checked", true);	
					var localdisplay=splitdisplay.join();
					
					
					localdisplay=localdisplay.replace(/,/gi,'/');//replace , with /
					
					document.getElementById(type+"n").setAttribute("value", localdisplay);
						
					}else{
					document.getElementById(splitdisplay[0]).setAttribute("checked", true);	
					document.getElementById(splitdisplay[0]+"n").setAttribute("value", splitdisplay[1]);
					}
					
	
				}  
		  
	  }
	  		if(sessionStorage['technicals']){
		  
				//set localdisplays now so we can use it again
					
			var localtechnicals=sessionStorage['technicals'].split(",");
				for(i=0;i<localtechnicals.length;i++){
					var splittechnical=localtechnicals[i].split("/");
					if(splittechnical.length>2){
						var type=splittechnical[0];
						splittechnical.splice(0,1);
					document.getElementById(type).setAttribute("checked", true);	
					var localtechnical=splittechnical.join();
					
					
					localtechnical=localtechnical.replace(/,/gi,'/');//replace , with /
					
					document.getElementById(type+"n").setAttribute("value", localtechnical);
						
					}else{
					document.getElementById(splittechnical[0]).setAttribute("checked", true);	
					document.getElementById(splittechnical[0]+"n").setAttribute("value", splittechnical[1]);
					}
					
	
				}  
		  
	  }
	  
	  	if(sessionStorage['advStartDate']){
			document.getElementById("advStartDate").setAttribute("value", sessionStorage['advStartDate']);
			
		}
		if(sessionStorage['advEndDate']){
			document.getElementById("advEndDate").setAttribute("value", sessionStorage['advEndDate']);
			
		}
		if(sessionStorage['advSymbol']){
			var advSymbol= document.getElementById("advSymbol");
			advSymbol.value=sessionStorage["advSymbol"];
		
			
		}

		if(sessionStorage["advType"]){
			
			var type=document.getElementById("advType");
			type.value=sessionStorage["advType"];	
		}
		





			</script>  
      
      
  </div>
    <br class="clear" />
  </div>
</div>
<div class="wrapper col6"></div>
<div class="wrapper col7">
  <div id="copyright">
    <p class="fl_left">Copyright &copy; 2011 - All Rights Reserved - <a href="#">Domain Name</a></p>
    <p class="fl_right">Template by <a href="http://www.os-templates.com/" title="Free Website Templates">OS Templates</a></p>
    <br class="clear" />
  </div>
</div>
</body>
</html>
